<template>
    <div>
        <el-table :data="$store.getters['specs/getSpecs']" border style="width: 100%">
            <el-table-column prop="id" label="规格编号" width="180">
            </el-table-column>
            <el-table-column prop="specsname" label="规格名称" width="180">
            </el-table-column>
            <el-table-column label="规格属性">
                <template slot-scope="item">
                    <div class="shu">
                        <el-button style="margin-left: 0;" v-for="item in item.row.attrs" size="mini" plain>{{ item }}</el-button>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="状态">
                <template slot-scope="item">
                    <div>
                        <el-button class="tai" type="success" plain size="mini">{{ item.row.status == 1 ? '启用' : '禁用' }}</el-button>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="item">
                    <div>
                        <el-button type="primary" icon="el-icon-edit" circle size="mini"
                            @click="edit(item.row.id)"></el-button>
                        <el-button type="danger" icon="el-icon-delete" circle size="mini"
                            @click="del(item.row.id)"></el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background layout="prev, pager, next" @current-change="changepage" :page-size="size" :total="total">
        </el-pagination>
    </div>
</template>
<script>
import {specsdelete} from '../../request/api'
import { mapGetters  } from 'vuex'
export default {
    data() {
        return {
        }
    },
    methods: {
        // 编辑
        edit(id) {
            this.$emit('edit', id)
        },
        // 删除
        del(id) {
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                specsdelete({id})
                .then(res=>{
                    if(res.code==200){
                        this.$store.dispatch('specs/GetSpecsInfo')
                        this.$store.dispatch('specs/GetCountInfo')
                        this.$message.success(res.msg)
                    }else{
                        this.$message.error(res.msg)
                    }
                })
                
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        changepage(index){
            console.log(index);
            this.$store.dispatch('specs/ChangePage',index)
        }

    },
    mounted() {
        console.log(this.$store);
        this.$store.dispatch('specs/GetSpecsInfo')
        this.$store.dispatch('specs/GetCountInfo')
    },
    computed: {
        ...mapGetters({
            size:'specs/getSize',
            total:'specs/getTotal'
        })
    },
    components: {}
}
</script>
<style scoped>
.el-pagination {
    position: absolute;
    right: 10px;
}
</style>